<?php
require_model('base.class');
class doctorAccount extends base {
    private $table = 'DoctorAccount';
    private $primary = 'Id';
    function __construct() {
        parent::__construct($this->table,$this->primary);
    }
    function GetBalanceByPatientId($patientId){
        return $this->get_item(array('PatientId'=>$patientId));
    }
    function GetBalanceByDoctorUserName($username) {
        return $this->get_item(array('UserName'=>$username));
    }
    function Deposit($balance, $username) {
        if($this->GetBalanceByPatientId($username)) {
            return $this->update_item(array('Balance'=>'Balance+'.$balance), array('UserName'=>$username), array('Balance'));
        }else {
            return $this->insert_item(array('UserName'=>$username, 'Balance'=>$balance));
        }
    }
    function Withdrawal($balance, $username) {
        if($this->GetBalanceByDoctorUserName($username)) {
            return $this->update_item(array('Balance'=>'Balance-'.$balance), array('UserName'=>$username), array('Balance'));
        }else {
            return false;
        }
    }
}